# Maintainer: Antoine Martin (ayakael) <dev@ayakael.net>
# Contributor: Antoine Martin (ayakael) <dev@ayakael.net>

# secfixes:
#   6.0.6-r0:
#     - CVE-2022-30184
#   6.0.8-r0:
#     - CVE-2022-34716
#   6.0.9-r0:
#     - CVE-2022-38013
#   6.0.10-r0:
#     - CVE-2022-41032
#   6.0.12-r0:
#     - CVE-2022-41089
#   6.0.13-r0:
#     - CVE-2023-21538
#   6.0.14-r0:
#     - CVE-2023-21808
#   6.0.16-r0:
#     - CVE-2023-28260
#   6.0.18-r0:
#     - CVE-2023-24895
#     - CVE-2023-24897
#     - CVE-2023-24936
#     - CVE-2023-29331
#     - CVE-2023-29337
#     - CVE-2023-33126
#     - CVE-2023-33128
#     - CVE-2023-33135
#   6.0.20-r0:
#     - CVE-2023-33127
#     - CVE-2023-33170
#   6.0.21-r0:
#     - CVE-2023-35390
#     - CVE-2023-38180
#     - CVE-2023-35391
#   6.0.22-r0:
#     - CVE-2023-36792
#     - CVE-2023-36793
#     - CVE-2023-36794
#     - CVE-2023-36796
#     - CVE-2023-36799
#   6.0.23-r0:
#     - CVE-2023-44487
#   6.0.24-r0:
#     - CVE-2023-36792
#     - CVE-2023-36793
#     - CVE-2023-36794
#     - CVE-2023-36796
#     - CVE-2023-36799
#     - CVE-2023-44487
#   6.0.25-r0:
#     - CVE-2023-36049
#     - CVE-2023-36558


pkgname=dotnet6-runtime
pkgver=6.0.25
_bldver=6.0.125-r0
pkgrel=0

_pkgver_macro=${pkgver%.*}
_pkgver_name=${_pkgver_macro//[.0]}
_bldver_ver=${_bldver%%-*}
pkgdesc="The .NET $_pkgver_macro Core runtime"
arch="x86_64 aarch64 armv7"
url="https://dotnet.microsoft.com/"
license="MIT"
depends="
	dotnet$_pkgver_name-hostfxr
	icu-data-full
	icu-libs
	"
makedepends="dotnet$_pkgver_name-build=$_bldver"
subpackages="
	aspnetcore$_pkgver_name-runtime:aspnetcore_runtime:noarch
	aspnetcore$_pkgver_name-targeting-pack:aspnetcore_targeting_pack:noarch
	dotnet$_pkgver_name-apphost-pack:apphost_pack
	dotnet$_pkgver_name-hostfxr
	dotnet$_pkgver_name-targeting-pack:targeting_pack:noarch
	dotnet-host:host
	"
provides="dotnet$_pkgver_name=$pkgver-r$pkgrel"
options="!check" # No test suite
source="dotnet.sh.in"
builddir="$srcdir"
_libdir="/usr/lib"

case $CARCH in
	x86_64) _dotnet_arch="x64";;
	aarch64) _dotnet_arch="arm64";;
	armv7) _dotnet_arch="arm";;
	armhf) _dotnet_arch="armv6";;
	*) _dotnet_arch="$CARCH";;
esac

build() {
	sed "s|%LIBDIR%|$_libdir/dotnet|" "$srcdir"/dotnet.sh.in > "$srcdir"/dotnet.sh
}

package() {
	install -dm 755 "$pkgdir"/$_libdir/dotnet/shared

	cp -r $_libdir/dotnet/bootstrap/$_bldver_ver/shared/Microsoft.NETCore.App "$pkgdir"/$_libdir/dotnet/shared/.
}

host() {
	pkgdesc="A generic driver for the .NET Core Command Line Interface"
	depends=""

	install -dm 755 \
		"$subpkgdir"/etc/profile.d \
		"$subpkgdir"/etc/dotnet \
		"$subpkgdir"/usr/bin \
		"$subpkgdir"/$_libdir/dotnet

	cp -r $_libdir/dotnet/bootstrap/$_bldver_ver/dotnet "$subpkgdir"/$_libdir/dotnet/.
	ln -s $_libdir/dotnet/dotnet "$subpkgdir"/usr/bin/dotnet
	echo "$_libdir/dotnet" > "$subpkgdir"/etc/dotnet/install_location
	echo "$_libdir/dotnet" > "$subpkgdir"/etc/dotnet/install_location_$_dotnet_arch
	install -Dm 644 "$srcdir"/dotnet.sh -t "$subpkgdir"/etc/profile.d/
}

hostfxr() {
	pkgdesc="The .NET host resolver contains the logic to resolve and select the right version of the .NET SDK or runtime to use."
	depends="dotnet-host"
	provides="dotnet-hostfxr-$_pkgver_macro=$pkgver-r$pkgrel"

	install -dm 755	"$subpkgdir"/$_libdir/dotnet

	cp -r $_libdir/dotnet/bootstrap/$_bldver_ver/host "$subpkgdir"/$_libdir/dotnet/.
}

aspnetcore_runtime() {
	pkgdesc="The ASP.NET $_pkgver_macro Core runtime"
	depends="dotnet$_pkgver_name-runtime"
	provides="aspnetcore-runtime-$_pkgver_macro=$pkgver-r$pkgrel"

	install -dm 755 "$subpkgdir"/$_libdir/dotnet/shared

	cp -r $_libdir/dotnet/bootstrap/$_bldver_ver/shared/Microsoft.AspNetCore.App "$subpkgdir"/$_libdir/dotnet/shared/.
}

apphost_pack() {
	pkgdesc="The .NET $_pkgver_macro Core apphost pack"
	provides="dotnet-apphost-pack-$_pkgver_macro=$pkgver-r$pkgrel"

	install -dm 755 "$subpkgdir"/$_libdir/dotnet/packs

	cp -r $_libdir/dotnet/bootstrap/$_bldver_ver/packs/Microsoft.NETCore.App.Host.* "$subpkgdir"/$_libdir/dotnet/packs/.
}

targeting_pack() {
	pkgdesc="The .NET $_pkgver_macro Core targeting pack"
	provides="dotnet-targeting-pack-$_pkgver_macro=$pkgver-r$pkgrel"

	install -dm 755 "$subpkgdir"/$_libdir/dotnet/packs

	cp -r $_libdir/dotnet/bootstrap/$_bldver_ver/packs/Microsoft.NETCore.App.Ref "$subpkgdir"/$_libdir/dotnet/packs/.
}

aspnetcore_targeting_pack() {
	pkgdesc="The ASP.NET $_pkgver_macro Core targeting pack"
	provides="aspnetcore-targeting-pack-$_pkgver_macro=$pkgver-r$pkgrel"

	install -dm 755	"$subpkgdir"/$_libdir/dotnet/packs

	cp -r $_libdir/dotnet/bootstrap/$_bldver_ver/packs/Microsoft.AspNetCore.App.Ref "$subpkgdir"/$_libdir/dotnet/packs/.
}

sha512sums="
c3f31956976b77198e72a3fef3427338b6b2961f8c121416040c1105de0ce8073e46f4c2e9ef22a001aee69cbe39621c2ddac988522693110071dfae42f2e2b7  dotnet.sh.in
"
